﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibHuman;

namespace Human
{
	/// <summary>
	/// Summary description for frmBangcap.
	/// </summary>
	public class frmBangcap : System.Windows.Forms.Form
	{
        private AccessData mDB = new AccessData();
        Language lan = new Language();
        string m_user = "";
        int flag = 0;
		private DataSet ds=new DataSet();
		private System.Windows.Forms.DataGrid dgrDanhMuc5;
        private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.TextBox txtTen;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtMa;
        private Label label3;
        private ComboBox cmbnhombc;
        private MenuStrip menuStrip1;
        private ToolStripMenuItem cậpNhậtNhómBằngBáoCáoToolStripMenuItem;
        private Label label4;
        private TextBox txt_stt;
        private Button btn_them;
        private Button btn_sua;
        private Button btn_luu;
        private Button btn_boqua;
        private Button btn_xoa;
        private Button btn_thoat;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmBangcap()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmBangcap));
            this.dgrDanhMuc5 = new System.Windows.Forms.DataGrid();
            this.panel1 = new System.Windows.Forms.Panel();
            this.btn_boqua = new System.Windows.Forms.Button();
            this.btn_thoat = new System.Windows.Forms.Button();
            this.btn_xoa = new System.Windows.Forms.Button();
            this.btn_luu = new System.Windows.Forms.Button();
            this.btn_sua = new System.Windows.Forms.Button();
            this.btn_them = new System.Windows.Forms.Button();
            this.txtTen = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.txtMa = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.cmbnhombc = new System.Windows.Forms.ComboBox();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.cậpNhậtNhómBằngBáoCáoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.label4 = new System.Windows.Forms.Label();
            this.txt_stt = new System.Windows.Forms.TextBox();
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMuc5)).BeginInit();
            this.panel1.SuspendLayout();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // dgrDanhMuc5
            // 
            this.dgrDanhMuc5.AlternatingBackColor = System.Drawing.Color.Lavender;
            this.dgrDanhMuc5.BackColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc5.BackgroundColor = System.Drawing.SystemColors.Control;
            this.dgrDanhMuc5.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dgrDanhMuc5.CaptionBackColor = System.Drawing.Color.LightSteelBlue;
            this.dgrDanhMuc5.CaptionForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc5.CaptionVisible = false;
            this.dgrDanhMuc5.DataMember = "";
            this.dgrDanhMuc5.FlatMode = true;
            this.dgrDanhMuc5.Font = new System.Drawing.Font("Tahoma", 8F);
            this.dgrDanhMuc5.ForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc5.GridLineColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMuc5.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
            this.dgrDanhMuc5.HeaderBackColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc5.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.dgrDanhMuc5.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc5.LinkColor = System.Drawing.Color.Teal;
            this.dgrDanhMuc5.Location = new System.Drawing.Point(8, 6);
            this.dgrDanhMuc5.Name = "dgrDanhMuc5";
            this.dgrDanhMuc5.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMuc5.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc5.RowHeaderWidth = 10;
            this.dgrDanhMuc5.SelectionBackColor = System.Drawing.Color.CadetBlue;
            this.dgrDanhMuc5.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc5.Size = new System.Drawing.Size(404, 277);
            this.dgrDanhMuc5.TabIndex = 16;
            this.dgrDanhMuc5.CurrentCellChanged += new System.EventHandler(this.dgrDanhMuc5_CurrentCellChanged);
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.btn_boqua);
            this.panel1.Controls.Add(this.btn_thoat);
            this.panel1.Controls.Add(this.btn_xoa);
            this.panel1.Controls.Add(this.btn_luu);
            this.panel1.Controls.Add(this.btn_sua);
            this.panel1.Controls.Add(this.btn_them);
            this.panel1.Location = new System.Drawing.Point(7, 380);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(409, 36);
            this.panel1.TabIndex = 127;
            this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
            // 
            // btn_boqua
            // 
            this.btn_boqua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_boqua.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_boqua.Image = global::Human.Properties.Resources.undo_2005;
            this.btn_boqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_boqua.Location = new System.Drawing.Point(208, 3);
            this.btn_boqua.Name = "btn_boqua";
            this.btn_boqua.Size = new System.Drawing.Size(65, 28);
            this.btn_boqua.TabIndex = 3;
            this.btn_boqua.Text = "&Bỏ qua";
            this.btn_boqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_boqua.UseVisualStyleBackColor = true;
            this.btn_boqua.Click += new System.EventHandler(this.btn_boqua_Click);
            // 
            // btn_thoat
            // 
            this.btn_thoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_thoat.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_thoat.Image = global::Human.Properties.Resources.close_r;
            this.btn_thoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_thoat.Location = new System.Drawing.Point(346, 3);
            this.btn_thoat.Name = "btn_thoat";
            this.btn_thoat.Size = new System.Drawing.Size(60, 28);
            this.btn_thoat.TabIndex = 5;
            this.btn_thoat.Text = "&Thoát";
            this.btn_thoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_thoat.UseVisualStyleBackColor = true;
            this.btn_thoat.Click += new System.EventHandler(this.btn_thoat_Click);
            // 
            // btn_xoa
            // 
            this.btn_xoa.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_xoa.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_xoa.Image = global::Human.Properties.Resources.delete_enabled;
            this.btn_xoa.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_xoa.Location = new System.Drawing.Point(279, 3);
            this.btn_xoa.Name = "btn_xoa";
            this.btn_xoa.Size = new System.Drawing.Size(60, 28);
            this.btn_xoa.TabIndex = 4;
            this.btn_xoa.Text = "    &Xóa";
            this.btn_xoa.UseVisualStyleBackColor = true;
            this.btn_xoa.Click += new System.EventHandler(this.btn_xoa_Click);
            // 
            // btn_luu
            // 
            this.btn_luu.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_luu.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_luu.Image = global::Human.Properties.Resources.save;
            this.btn_luu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_luu.Location = new System.Drawing.Point(142, 3);
            this.btn_luu.Name = "btn_luu";
            this.btn_luu.Size = new System.Drawing.Size(60, 28);
            this.btn_luu.TabIndex = 2;
            this.btn_luu.Text = "   &Lưu";
            this.btn_luu.UseVisualStyleBackColor = true;
            this.btn_luu.Click += new System.EventHandler(this.btn_luu_Click);
            // 
            // btn_sua
            // 
            this.btn_sua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_sua.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_sua.Image = global::Human.Properties.Resources.quick_edit;
            this.btn_sua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_sua.Location = new System.Drawing.Point(76, 3);
            this.btn_sua.Name = "btn_sua";
            this.btn_sua.Size = new System.Drawing.Size(60, 28);
            this.btn_sua.TabIndex = 1;
            this.btn_sua.Text = "   &Sửa";
            this.btn_sua.UseVisualStyleBackColor = true;
            this.btn_sua.Click += new System.EventHandler(this.btn_sua_Click);
            // 
            // btn_them
            // 
            this.btn_them.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_them.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_them.Image = global::Human.Properties.Resources.add;
            this.btn_them.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_them.Location = new System.Drawing.Point(11, 3);
            this.btn_them.Name = "btn_them";
            this.btn_them.Size = new System.Drawing.Size(60, 28);
            this.btn_them.TabIndex = 0;
            this.btn_them.Text = "   &Thêm";
            this.btn_them.UseVisualStyleBackColor = true;
            this.btn_them.Click += new System.EventHandler(this.btn_them_Click);
            // 
            // txtTen
            // 
            this.txtTen.BackColor = System.Drawing.Color.White;
            this.txtTen.Enabled = false;
            this.txtTen.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtTen.Location = new System.Drawing.Point(97, 312);
            this.txtTen.Name = "txtTen";
            this.txtTen.Size = new System.Drawing.Size(319, 20);
            this.txtTen.TabIndex = 1;
            this.txtTen.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtTen_KeyDown);
            // 
            // label2
            // 
            this.label2.BackColor = System.Drawing.SystemColors.Control;
            this.label2.ForeColor = System.Drawing.Color.DarkBlue;
            this.label2.Location = new System.Drawing.Point(94, 296);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(77, 13);
            this.label2.TabIndex = 125;
            this.label2.Text = "Tên bằng cấp ";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label1
            // 
            this.label1.BackColor = System.Drawing.SystemColors.Control;
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(14, 296);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(73, 13);
            this.label1.TabIndex = 123;
            this.label1.Text = "Mã bằng cấp ";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtMa
            // 
            this.txtMa.BackColor = System.Drawing.Color.White;
            this.txtMa.Enabled = false;
            this.txtMa.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtMa.Location = new System.Drawing.Point(18, 313);
            this.txtMa.Name = "txtMa";
            this.txtMa.Size = new System.Drawing.Size(64, 20);
            this.txtMa.TabIndex = 0;
            this.txtMa.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtMa_KeyDown);
            // 
            // label3
            // 
            this.label3.BackColor = System.Drawing.SystemColors.Control;
            this.label3.ForeColor = System.Drawing.Color.DarkBlue;
            this.label3.Location = new System.Drawing.Point(94, 338);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(89, 13);
            this.label3.TabIndex = 123;
            this.label3.Text = "Nhóm bằng cấp :";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // cmbnhombc
            // 
            this.cmbnhombc.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbnhombc.Enabled = false;
            this.cmbnhombc.FormattingEnabled = true;
            this.cmbnhombc.Location = new System.Drawing.Point(97, 354);
            this.cmbnhombc.Name = "cmbnhombc";
            this.cmbnhombc.Size = new System.Drawing.Size(319, 21);
            this.cmbnhombc.TabIndex = 3;
            this.cmbnhombc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cmbnhombc_KeyDown);
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.cậpNhậtNhómBằngBáoCáoToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(425, 24);
            this.menuStrip1.TabIndex = 129;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // cậpNhậtNhómBằngBáoCáoToolStripMenuItem
            // 
            this.cậpNhậtNhómBằngBáoCáoToolStripMenuItem.Name = "cậpNhậtNhómBằngBáoCáoToolStripMenuItem";
            this.cậpNhậtNhómBằngBáoCáoToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F5;
            this.cậpNhậtNhómBằngBáoCáoToolStripMenuItem.Size = new System.Drawing.Size(177, 20);
            this.cậpNhậtNhómBằngBáoCáoToolStripMenuItem.Text = "Cập nhật nhóm bằng báo cáo";
            this.cậpNhậtNhómBằngBáoCáoToolStripMenuItem.Visible = false;
            this.cậpNhậtNhómBằngBáoCáoToolStripMenuItem.Click += new System.EventHandler(this.cậpNhậtNhómBằngBáoCáoToolStripMenuItem_Click);
            // 
            // label4
            // 
            this.label4.BackColor = System.Drawing.SystemColors.Control;
            this.label4.ForeColor = System.Drawing.Color.DarkBlue;
            this.label4.Location = new System.Drawing.Point(15, 336);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(34, 13);
            this.label4.TabIndex = 133;
            this.label4.Text = "STT: ";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txt_stt
            // 
            this.txt_stt.BackColor = System.Drawing.Color.White;
            this.txt_stt.Enabled = false;
            this.txt_stt.ForeColor = System.Drawing.Color.DarkBlue;
            this.txt_stt.Location = new System.Drawing.Point(18, 354);
            this.txt_stt.Name = "txt_stt";
            this.txt_stt.Size = new System.Drawing.Size(64, 20);
            this.txt_stt.TabIndex = 2;
            this.txt_stt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtHeso_KeyDown);
            // 
            // frmBangcap
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(425, 421);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.txt_stt);
            this.Controls.Add(this.cmbnhombc);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.txtTen);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtMa);
            this.Controls.Add(this.dgrDanhMuc5);
            this.Controls.Add(this.menuStrip1);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MainMenuStrip = this.menuStrip1;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmBangcap";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Danh mục bằng cấp";
            this.Load += new System.EventHandler(this.frmBangcap_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMuc5)).EndInit();
            this.panel1.ResumeLayout(false);
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void frmBangcap_Load(object sender, System.EventArgs e)
		{
            flag = 0;
            bangcap();
            loadbcbc();
            refresh_Text();
            string str = " qdwf";
		}
		private void bangcap() 	
		{
			DataSet ds1=new DataSet();
			ds1=mDB.get_data("SELECT a.mabangcap,a.tenbang,a.mabc,a.stt ,b.tenbang as tenbangbc FROM "+mDB.user+".bangcap a left join " + mDB.user + ".bangcapbc b on a.mabc=b.mabang order by stt");
			dgrDanhMuc5.DataSource=null;
			dgrDanhMuc5.TableStyles.Clear();
			DataGridTableStyle ts = new DataGridTableStyle();
			ts.MappingName = ds1.Tables[0].TableName;
		
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			
			DataGridTextBoxColumn TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "mabangcap";
			TextCol1.HeaderText = lan.Change_language_MessageText("Mã bằng cấp");
			TextCol1.Width = 80;
			TextCol1.ReadOnly=true;
			TextCol1.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol1);
			dgrDanhMuc5.TableStyles.Add(ts);
		
			DataGridTextBoxColumn TextCol2=new DataGridTextBoxColumn();
			TextCol2.MappingName = "tenbang";
			TextCol2.HeaderText = lan.Change_language_MessageText("Tên bằng cấp");
			TextCol2.Width = 150;
			TextCol2.ReadOnly=true;
			TextCol2.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol2);
			dgrDanhMuc5.TableStyles.Add(ts);

            DataGridTextBoxColumn TextCol3 = new DataGridTextBoxColumn();
            TextCol3.MappingName = "tenbangbc";
            TextCol3.HeaderText = lan.Change_language_MessageText("Nhóm báo cáo");
            TextCol3.Width = 150;
            TextCol3.ReadOnly = true;
            TextCol3.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol3);
            dgrDanhMuc5.TableStyles.Add(ts);

            DataGridTextBoxColumn TextCol4 = new DataGridTextBoxColumn();
            TextCol4.MappingName = "stt";
            TextCol4.HeaderText = lan.Change_language_MessageText("Số TT");
            TextCol4.Width = 40;
            TextCol4.ReadOnly = true;
            TextCol4.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol4);
            dgrDanhMuc5.TableStyles.Add(ts);
		
			ts.DataGrid.DataSource=ds1.Tables[0];
            CurrencyManager cm = (CurrencyManager)BindingContext[dgrDanhMuc5.DataSource, dgrDanhMuc5.DataMember];
            DataView dv = (DataView)cm.List;
            dv.AllowNew = false;
            dv.AllowEdit = false;
            dv.AllowDelete = false;
		}

		private void Ena_control(bool ena)
		{
			btn_them.Enabled=ena;
			btn_sua.Enabled=ena;
			btn_luu.Enabled=!ena;
			btn_boqua.Enabled=!ena;
			btn_xoa.Enabled=ena;
			btn_thoat.Enabled=ena;
		}
		private void Ena_textbox(bool ena)
		{
            txtTen.Enabled = ena;
            cmbnhombc.Enabled = ena;
            txt_stt.Enabled = ena;
		}
		private void clear_Text()
		{			
			txtTen.Clear();
		}
		private void refresh_Text()
		{
			int i=dgrDanhMuc5.CurrentRowIndex;
			if(i>=0)
			{
				txtMa.Text=dgrDanhMuc5[i,0].ToString();
				txtTen.Text=dgrDanhMuc5[i,1].ToString();
                cmbnhombc.Text = dgrDanhMuc5[i, 2].ToString();
                txt_stt.Text = dgrDanhMuc5[i, 3].ToString();
			}
		}
        private bool kemtra(string mabangcap)
        {
            bool flag = false;
            try
            {
                flag = mDB.get_data("select count(*) as tong from " + mDB.user + ".llnv where td_nnghiep='" + mabangcap + "'").Tables[0].Rows[0][0].ToString().Equals("0");
            }
            catch
            {
                flag = false;
            }
            if (!flag)
                MessageBox.Show(lan.Change_language_MessageText("Bằng cấp đã sử dụng không thể hủy!"),AccessData.Msg);
            return flag;
        }
	
		private void dgrDanhMuc5_CurrentCellChanged(object sender, System.EventArgs e)
		{
			try
			{
				refresh_Text();
			}
            catch (Exception ex) { string s = ex.Message; }
		}

        private void txtMa_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode==Keys.Enter)
                SendKeys.Send("{Tab}");
        }

        private void txtTen_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");
        }

        private void loadbcbc()
        {
            try
            {
                cmbnhombc.DataSource = mDB.get_data("select mabang,tenbang from " + mDB.user + ".bangcapbc ").Tables[0];
                cmbnhombc.DisplayMember = "tenbang";
                cmbnhombc.ValueMember = "mabang";
            }
            catch  { }
        }

        private void update_bc()
        {
            try
            {
                DataSet ds_ = new DataSet();
                ds_.ReadXml(@"xml\NHANSU.BANGCAP.XML");
                mDB.Execute_data("delete from " + mDB.user + ".bangcapbc");
                foreach (DataRow r in ds_.Tables[0].Rows)
                {
                    mDB.Execute_data("insert into " + mDB.user + ".bangcapbc(mabang,tenbang) values('" + r["mabangcap"].ToString() + "','" + r["tenbang"].ToString() + "')");
                }
            }
            catch
            { }
        }

        private void cậpNhậtNhómBằngBáoCáoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            update_bc();
        }

        private void txtHeso_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab},{F4}");
        }

        private void cmbnhombc_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btn_luu.Focus();
        }
        private string max_id()
        {
            int m_tam = 0;
            ds = mDB.get_data("SELECT Max(to_number(mabangcap,99)) FROM " + m_user + ".bangcap");
            if (ds.Tables[0].Rows.Count > 0)
                if (ds.Tables[0].Rows[0][0].ToString().Trim() == "")
                    m_tam = 1;
                else
                    m_tam = int.Parse(ds.Tables[0].Rows[0][0].ToString()) + 1;
            else
                m_tam = 1;
            return m_tam.ToString();//.PadLeft(1, '0');
        }
        private void btn_them_Click(object sender, EventArgs e)
        {
            Ena_control(false);
            Ena_textbox(true);
            clear_Text();
            flag = 0;
            m_user = mDB.user;
            txtMa.Text = max_id();
          
            txtTen.Focus();
        }

        private void btn_sua_Click(object sender, EventArgs e)
        {
            flag = 1;
            Ena_control(false);
            Ena_textbox(true);
            txtTen.Focus();
        }

        private void btn_luu_Click(object sender, EventArgs e)
        {
            try
            {
                int stt = 0,m_id=0;
                stt = txt_stt.Text.Trim()!="" ? Int32.Parse(txt_stt.Text):0;
                if (flag == 0)
                {
                    m_id = Int32.Parse(max_id());
                    txtMa.Text = m_id.ToString().PadLeft(2, '0');
                }
                else
                {
                    if (txtMa.Text != "")
                        m_id = Int32.Parse(txtMa.Text.ToString());
                }
                mDB.upd_DMBANGCAP(txtMa.Text, txtTen.Text, cmbnhombc.SelectedValue.ToString(), stt);
                flag = 0;
                bangcap();
                Ena_control(true);
                Ena_textbox(false);
                btn_them.Focus();
            }
            catch { }
        }

        private void btn_boqua_Click(object sender, EventArgs e)
        {
            Ena_control(true);
            Ena_textbox(false);
            refresh_Text();
            btn_thoat.Focus();
        }

        private void btn_xoa_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show(lan.Change_language_MessageText("Đồng ý huỷ thông tin này?"),AccessData.Msg, MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes && kemtra(txtMa.Text.Trim()))
            {
                mDB.get_data("DELETE  FROM " + mDB.user + ".bangcap WHERE mabangcap='" + txtMa.Text.Trim() + "'");
            }
            bangcap();
            refresh_Text();		
        }

        private void btn_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }
	}
}
